<%@ page language="java" contentType="text/html; charset=UTF-8" 
 pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="index.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <title>主页</title>
    <meta name="keywords" content="耶回收">
    <meta name="description" content="耶回收">
</head>
<style type="text/css">

td{
font-size:15px;

}

.ipt-text{
width: 120px;
height: 30px;
}

/* body .demo-class .layui-layer-title{background:#5eb95e;color:#fff;}
body .demo-class .layui-layer-btn .layui-layer-btn0 {background:#5eb95e;border:none;} */

</style>
<body>
<!--_表格--开始-->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        企业回收
        <span class="c-gray en">&gt;</span>
        企业回收管理
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
              <form action="toEnterprise" onsubmit="return checkPhone()" method="POST">
                起始时间：<input  name="addtime" type="date" class="input-text" style="width:140px;"/>
                          <input type="hidden"  value="${searchinfo.addtime }" id="addtime"/>
                结束时间 <input   name="updatetime" type="date"  class="input-text" style="width:140px;"/>
                           <input type="hidden" value="${searchinfo.updatetime }  id="updatetime"/>
                           <input value="${searchinfo.companyname}" type="text" name="companyname" placeholder="企业名称" style="width:250px" class="input-text">
			                <input value="${searchinfo.phone}" type="text" name="phone" placeholder="输入手机号查询" style="width:250px" class="input-text">
			                <button id="searchitem" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i>搜索企业回收</button></form> 
            </div>
             <!-- 搜索模块结束 -->
            <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
				 <shiro:hasPermission name="commodity"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a></shiro:hasPermission>
				</span>
                <span class="r">共有数据：<strong>${pageinfo.total }</strong> 条</span>
            </div>   
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                    <tr class="text-c">
                         <th width="25"><input class="ce" type="checkbox" name="" value=""></th>
                         <th width="30">序号</th>
                         <th width="140">企业名称</th>
                         <th width="50">客户姓名</th>
                         <th width="70">联系电话</th>
                         <th width="60">评估金额</th>
                         <th width="120">添加时间</th>
                         <th width="120">更新时间</th>
                         <th width="40">状态</th>
                         <th width="40">操作</th>
                    </tr>
                    </thead>
                    <tbody id="tb">
                      <c:forEach items="${pageinfo.list}" var="ep">
                    <c:if test="${pageinfo.total==0}">暂无数据</c:if>
                     <tr class="text-c">
                       <td ><input type="checkbox" class="ce" value="${ep.id }" name=""></td>
                        <td  width="30">${ep.id }</td>
                        <td ><a href="javascript:void(0)" style="color:blue" class="text-primary" onclick="backitem_get('企业回收详情','getOneEnterpriseback?id=${ep.id}')" title="查看详细信息">${ep.companyname }</a></td>
                         <td  width="40">${ep.clientname }</td>
                          <td  width="40">${ep.phone }</td>
                        <td  width="40">${ep.price}</td>
                       <td  width="60"> ${ep.addtime }</td >
                       <td  width="60">${ep.updatetime }</td>
                       
               <c:if test="${ep.status==0}"> <td class="td-status"><span class="label label-defaunt radius">未估价</span></td></c:if>
               <c:if test="${ep.status==1}"> <td class="td-status"><span class="label label-success radius">已估价</span></td></c:if>
                        <td class="f-14 td-manage">
              <%--  <c:if test="${ep.status==1}"><a style="text-decoration:none" onClick="article_stop(this,'${backitem.id }')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a></c:if>
               <c:if test="${ep.status==0}"><a style="text-decoration:none" onClick="article_start(this,'${backitem.id }')" href="javascript:;" title="评估"><i class="Hui-iconfont">&#xe603;</i></a></c:if>            --%>
                            <a style="text-decoration:none" class="ml-5" onclick="backitem_edit('企业回收信息-编辑','editEnterpriseback?id=${ep.id}')" title="查看详细信息"  title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                           <a style="text-decoration:none" class="ml-5" onclick="backitem_del(this,${ep.id })" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
                        <strong>一共${pageinfo.pages}页</strong>
                        <input id="npage" type="hidden" value="${pageinfo.pageNum}"/>
                        <strong>当前页${pageinfo.pageNum}</strong>
                 <span class="layui-breadcrumb">
                 <c:if test="${pageinfo.pageNum>1}"><a href="toEnterprise?npage=1&phone=${searchinfo.phone}&addtime=${searchinfo.addtime}&updatetime=${searchinfo.updatetime}&companyname=${searchinfo.companyname}">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:void(0)">第一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==1}"><a href="javascript:void(0)">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum>1}"><a href="toEnterprise?npage=${pageinfo.prePage}&phone=${searchinfo.phone}&addtime=${searchinfo.addtime}&updatetime=${searchinfo.updatetime}&companyname=${searchinfo.companyname}">上一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages }"><a href="toEnterprise?npage=${pageinfo.nextPage}&phone=${searchinfo.phone}&addtime=${searchinfo.addtime}&updatetime=${searchinfo.updatetime}&companyname=${searchinfo.companyname}">下一页</a></c:if>
                 <c:if test="${pageinfo.pageNum==pageinfo.pages }"><a href="javascript:void(0)">下一页</a></c:if> 
                 <c:if test="${pageinfo.pageNum==pageinfo.pages}">  <a href="javascript:void(0)">最后一页</a></c:if>
                 <c:if test="${pageinfo.pageNum<pageinfo.pages}"><a href="toEnterprise?npage=${pageinfo.pages}&phone=${searchinfo.phone}&addtime=${searchinfo.addtime}&updatetime=${searchinfo.updatetime}&companyname=${searchinfo.companyname}">最后一页</a></c:if>
             </span>
         </article>
        </div>
  </section>
<script type="text/javascript">

    $(".ce").attr("checked",false);


    $('.table-sort').dataTable({
        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable":false,"aTargets":[0,8]}// 不参与排序的列
        ]
    });

    /* 编辑商品 */
    function backitem_edit(title,url,id,w,h){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
       
        
    }
    
    
    layer.open({
		type: 2,
		area: [w+'px', h +'px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: title,
		content: url
		 
	});  
    
    /*查看商品详情*/
    function backitem_get(title,url){
        var index = layer.open({
            type: 2,
            skin:'demo-class',
            anim:3,
            shadeClose:true,
            title: title,
            area: [630+'px', 600 +'px'],
            shade:0.3,
            content:url
        });
        
    }
    
    
    //编辑修改企业回收信息
    function backitem_edit(title,url){
        var index = layer.open({
            type: 2,
            anim:3,
            skin:'demo-class',
            title: title,
            area: [700+'px', 400 +'px'],
            shade:0.2,
            content:url,
            end:function(){
            	var npage = $("#npage").val();
            console.log($("#addtime").val());
            	/* var addtime = $("#addtime").val();
            	var updatetime = $("#updatetime").val(); */
                window.location.href="toEnterprise?npage="+npage/* +"&addtime="+addtime+"&updatetime="+updatetime; */
                }
           
        });
        
    }

   /*回收商品-删除*/
   function backitem_del(obj,id){
       layer.confirm('确认要删除吗？',{ btn: ["确定","取消"],skin:'demo-class'},function(index){
           $.ajax({
               type:"POST",
               url:"deleteEnterpriseback",
               data:{"id":id},
               dataType: "json",
               success: function(data){
            	 layer.close(index);
                 $(obj).parents("tr").remove();
                 layer.msg("删除成功！",{icon: 1,time:1000});
               //window.location.href = window.location.href;                	
               },
               error:function(data) {
               },
           });
       });
       
       /*  $(obj).parents("tr").remove();
      	$("#msg").html("删除成功！").show();
        $("#msg").animate({
	           opacity: "hide"
	       }, 4000); */
   }

  //改变商品状态的ajax 方法
  function changeBackStatu(id,url){
	  
	  $.ajax({
          type: "POST",
          url:url,
          data:{id:id},
          dataType:"json",
          success: function(data){
        	  
          },
          error:function(data) {
              console.log("ajax通讯异常");
          }
      });
	  
  }
   
   
   

    
    /*商品下架*/
    function article_stop(obj,id){
        layer.confirm('确认要下架吗？',{ btn: ["确定","取消"] },function(index){
        	$.ajax({
                type: "POST",
                url:"changeBackStatus",
                data:{"id":id},
                dataType:"json",
                success: function(data){
                	 layer.close(index);
                	$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_start(this,'+id+')" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
                    $(obj).remove();
                    layer.msg('已下架!',{icon: 5,time:1000});	
              	  
                },
                error:function(data) {
                    layer.msg("ajax异常！操作失败");
                }
            });  
          
        });
    }
    
    /*批量删除*/
    function datadel(){
 	  console.log("-----进入批量删除的方法------");
 	  var tds = new Array();
        //获取所有的tr标签元素集合
 	   tds=document.getElementById("tb").getElementsByTagName("tr");
 		  var td_s = new Array();
 		 
 		  for(var i=0;i<tds.length;i++){
 		  var tdc =tds[i].getElementsByTagName("td")[0].getElementsByTagName("input")[0];
 		  var tdcheck =$(tdc);
 		  console.log(tdcheck.is(":checked"));
 		  if(tdcheck.is(":checked")){
 		    //如果td被选中 则td的id值放入数组中
 			td_s.push(tdcheck.val());
 		    
 		 } 
 		  } 
 	   //判断是否有被选中删除的记录 
 	   if(td_s.length>0){
 		   //发出批量删除ajax 删除请求
 		   layer.confirm('确认要删除吗？',{ btn: ["确定","取消"] },function(index){
 	           $.ajax({
 	               type: 'POST',
 	               url: 'deleteEnterprisebacks',
 	               data:{"td_s":td_s},
 	               dataType: 'json',
 	               success: function(val){
 	               	layer.close(index);
 	               layer.msg("删除成功",{icon:1,time:2000});
 	               	location.reload();              	
 	               },
 	               error:function(data) {
 	                   console.log(data.msg);
 	               },
 	           });
 	       });
 	   }else{ 
 		   
 		   layer.msg("请选择要删除的数据！",{time:2000});
 		 
 	   }
 	   
    } 
    
    
    
    

    /*商品上架*/
    function article_start(obj,id){
        layer.confirm('确认要上架吗？',{ btn: ["确定","取消"] },function(index){
        	 $.ajax({
                 type: "POST",
                 url:"changeBackStatus",
                 data:{"id":id},
                 dataType:"json",
                 success: function(data){
                	 layer.close(index);
                	 $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="article_stop(this,'+id+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
                     $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">评估中</span>');
                     $(obj).remove();
                     layer.msg('已上架!',{icon: 6,time:1000});
               	  
                 },
                 error:function(data) {
                	 layer.msg("ajax异常！操作失败");
                 }
             });
        	
        	
           
        });
    }

    /*商品上线*/
    function article_shenqing(obj,id){
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
        $(obj).parents("tr").find(".td-manage").html("");
        layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
    }
</script>
</body>
</html>